﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using PQT.API;
using PQT.Common;
using System.Data.Common;
using System.Text;
using System.Configuration;

namespace cbmobile.BLC
{
    public class DBConnection
    {
        string ConnectionString = string.Empty;
        

        public DBConnection()
        {
            ConnectionString = SessionConStr;
        }

        public DBConnection(string p_name)
        {
            ConnectionString = ConfigurationManager.ConnectionStrings[p_name].ConnectionString;
        }

        public SqlConnection InitConnection()
        {
            SqlConnection con = new SqlConnection(ConnectionString);
            return con;
        }

        private string SessionConStr
        {
            get
            {
                if (HttpContext.Current.Session["ConnectionString"] == null || string.IsNullOrEmpty(HttpContext.Current.Session["ConnectionString"].ToString()))
                {
                    string ConnectionStr = System.Configuration.ConfigurationManager.ConnectionStrings["PQT"].ToString();
                    HttpContext.Current.Session["ConnectionString"] = ConnectionStr;
                }
                return HttpContext.Current.Session["ConnectionString"].ToString();
            }
        }
    }
}